package com.demo.controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;

import com.generator.tools.restful.CommonResult;
import com.demo.entity.User;
import com.demo.service.IUserService;
import com.generator.tools.pagehelper.CommonPage;

import java.util.List;

/**
* @author blue demon
* @date 2020/02/08
*/
@Api(tags = "")
@RestController
@RequestMapping("/user")
public class UserController {

	@Autowired
	private IUserService userService;


	@ApiOperation(" 查询列表")
	@PostMapping("/selectUserList")
	public CommonResult<?> selectUserList(User user,
		@RequestParam(value = "pageNum",defaultValue = "1",required = false) int pageNum,
		@RequestParam(value = "pageSize",defaultValue = "10",required = false)int pageSize){
		List<User> users = userService.selectUserList(user,pageNum,pageSize);
		return CommonResult.success(CommonPage.restPage(users));
	}

	@ApiOperation("通过Id查询")
	@GetMapping("/selectUserById/{userId}")
	public CommonResult<?> selectUserById(@PathVariable("userId") Long userId){
		return CommonResult.success(userService.selectUserById(userId));
	}
	
	@ApiOperation("新增")
	@PostMapping("/insertUser")
	public CommonResult<?> insertUser(User user){
		return CommonResult.success(userService.insertUser(user));
	}


	@ApiOperation("修改信息")
	@PostMapping("/updateUser")
	public CommonResult<?> updateUser(User user){
		return CommonResult.success(userService.updateUser(user));
	}

	@ApiOperation("通过id删除")
	@PostMapping("/deleteUserById/{userId}")
	public CommonResult<?> deleteUserById(@PathVariable("userId") Long userId){
		return CommonResult.success(userService.deleteUserById(userId));
	}

	@ApiOperation("通过id批量删除")
	@PostMapping("/deleteList")
	public CommonResult<?> deleteUserByIds(String userIds){
		return CommonResult.success(userService.deleteUserByIds(userIds));
	}
}